/**
 * 
 */
package neptune.manager.model.topology;

/**
 * @author Roberto Bifulco [info@robertobifulco.it, robertobifulco.it]
 * 
 */
public class OLPIEndPoint implements EndPoint {

	private String nodeId;
	private String interfaceId;

	/**
	 * @param address
	 * @param nodeId
	 * @param interfaceId
	 */
	public OLPIEndPoint(String nodeId, String interfaceId) {
		this.nodeId = nodeId;
		this.interfaceId = interfaceId;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof OLPIEndPoint))
			return false;

		OLPIEndPoint ep = (OLPIEndPoint) obj;

		if (nodeId.equals(ep.getNodeId())
				&& interfaceId.equals(ep.getInterfaceId()))
			return true;
		return false;
	}

	@Override
	public String getInterfaceId() {
		return interfaceId;
	}

	@Override
	public int getMultiplexingTech() {
		return Link.ONE_LINK_PER_INTERFACE;
	}

	@Override
	public String getNodeId() {
		return nodeId;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * neptune.manager.model.topology.EndPoint#isThisEndPoint(neptune.manager
	 * .model.topology.NetworkInterface)
	 */
	/**
	 * Verifica la corrispondenza fra interfaccia ed endpoint in base al
	 * confronto degli id di nodo e interfaccia.
	 */
	@Override
	public boolean isThisEndPoint(NetworkInterface netInterface) {
		if (netInterface == null)
			return false;
		if (netInterface.getInterfaceName() == null
				|| netInterface.getParentNode() == null)
			return false;
		if (netInterface.getParentNode().equals(nodeId)
				&& netInterface.getInterfaceName().equals(interfaceId))
			return true;
		return false;
	}

	public void setInterfaceId(String interfaceId) {
		this.interfaceId = interfaceId;
	}

	public void setNodeId(String nodeId) {
		this.nodeId = nodeId;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "OLPI end point: " + nodeId + " " + interfaceId;
	}

}
